(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.custAcct.deleteRejectController', deleteController);
	deleteController.$inject = [ '$scope', '$q', 'Constants', 'layoutConfig', 'validatorConfig', 'gridService', 'authService', 'modalService', 'custAcctService', 'storageService' ];
	function deleteController($scope, $q, Constants, layoutConfig, validatorConfig, gridService, authService, modalService, custAcctService, storageService) {
		var ctrl = this, params = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.custAcct = {};
		custAcctService.initFunction(ctrl);
		
		ctrl.init = function() {
			custAcctService.initOptions().then(function(response){
				ctrl.custAcctTypeOptions = response.custAcctTypeOptions;
				ctrl.ccyOptions = response.ccyOptions;
				ctrl.paycodeCatOptions = response.paycodeCatOptions;
				ctrl.allPartyTypeOptions = response.allPartyTypeOptions;
				ctrl.yesNoOptions = response.yesNoOptions;
				ctrl.yesNoOptionsb = response.yesNoOptionsb;
				ctrl.swiftCaseList = response.swiftCaseList;
				ctrl.accountPatterns = response.accountPatterns;
				ctrl.accountPatternsTwo = response.accountPatternsTwo;
				
				ctrl.partyCountrys = response.countryOptionAll;
				ctrl.partyStates = response.stateOptionAll;
				ctrl.partyCitys = response.cityOptionAll;
				ctrl.stateList = response.stateList;
				ctrl.cityList = response.cityList;
				ctrl.partyStatesCatch = response.stateOptionAll;
				ctrl.partyCitysCatch = response.cityOptionAll;
							
				authService.deleteReject(params).then(function(response) {
					if (response.data && response.data.model && response.data.task) {
						ctrl.custAcct = response.data.model;
						ctrl.custAcct.taskId = response.data.task.taskId;
						ctrl.custAcct.siteCode = storageService.getUserInfo().siteCode;
						ctrl.custAcct.custAcctSwift = ctrl.custAcct.custAcctSwift || {};
						ctrl.custAcct.custAcctSwift.payPartyList = ctrl.custAcct.custAcctSwift.payPartyList || [];
						ctrl.initPyPartyTabs();
					}
				});
			});
		};
		
		ctrl.deleteRejectSubmit = function() {
			modalService.openConfirmDialogs({
				'messages' : [ {msg : 'title.dialog.confirm.delete', args : [ctrl.custAcct.primaryKey]} ],
				'btnCallback' : {
					'ok' : function() {
						authService.deleteRejectSubmit(ctrl.custAcct).then(deleteSuccessful, deleteFailed);
					}
				}
			});
		};
		
		ctrl.deleteRejectCancel = function() {
			modalService.openConfirmDialogs({
				'messages' : [ {msg : 'title.dialog.confirm.cancel', args : [ctrl.custAcct.primaryKey]} ],
				'btnCallback' : {
					'ok' : function() {
						authService.deleteRejectCancel(ctrl.custAcct).then(cancelSuccessful, cancelFailed);
					}
				}
			});
		};
		
		function deleteSuccessful(response) {
			modalService.openAcknowledgeDialogs({
				'messages' : [ 'title.dialog.successful.delete' ],
				'btnCallback' : {
					'close' : function() {
						$scope.go('cda.workflow.wfSetup.list');
					}
				},
				'redirections' : [ {
					'name' : 'title.infobar.workflow.list',
					'state' : 'cda.workflow.wfSetup.list',
					'params' : {}
				}, {
					'name' : 'title.infobar.custAcct.list',
					'state' : 'cda.custAcct.list',
					'params' : {}
				}]
			});
		}

		function deleteFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}
		
		function cancelSuccessful(response) {
			modalService.openAcknowledgeDialogs({
				'messages' : [ 'title.dialog.successful.cancel' ],
				'btnCallback' : {
					'close' : function() {
						$scope.go('cda.workflow.wfSetup.list');
					}
				},
				'redirections' : [ {
					'name' : 'title.infobar.workflow.list',
					'state' : 'cda.workflow.wfSetup.list',
					'params' : {}
				}, {
					'name' : 'title.infobar.custAcct.list',
					'state' : 'cda.custAcct.list',
					'params' : {}
				}]
			});
		}

		function cancelFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}
	}
})(angular);
